package com.bjgzy.rating.mvp.ui.adapter;

import android.graphics.drawable.AnimationDrawable;
import android.support.annotation.Nullable;
import android.widget.ImageView;

import com.bjgzy.rating.R;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.eduhzy.ttw.commonsdk.entity.EntriesDetailData;
import com.eduhzy.ttw.commonsdk.holder.AutoBaseViewHolder;

import java.util.List;

/**
 * Created by xubo on 2018/2/5.
 */

public class RecordListenAdapter extends BaseQuickAdapter<EntriesDetailData.AttachmentListBean, AutoBaseViewHolder> {

    private int playPosition = -1;


    public int getPlayPosition() {
        return playPosition;
    }

    public void setPlayPosition(int playPosition) {
        this.playPosition = playPosition;
    }

    public RecordListenAdapter(int layoutResId, @Nullable List<EntriesDetailData.AttachmentListBean> data) {
        super(layoutResId, data);
    }

    @Override
    protected void convert(AutoBaseViewHolder helper, EntriesDetailData.AttachmentListBean item) {
        helper.setText(R.id.title_tv, item.getDisplayName());
        ImageView imageView = helper.getView(R.id.play_status_iv);
        imageView.setBackgroundResource(R.drawable.rating_anim_sound_play);
        helper.setGone(R.id.pb_sending, item.isShowloading());
        AnimationDrawable animationDrawable = (AnimationDrawable) imageView.getBackground();
        if (item.isPlay()) {
            // 把动画资源设置为imageView的背景,也可直接在XML里面设置
            if (animationDrawable != null) {
                animationDrawable.start();
            }
        } else {
            if (animationDrawable != null) {
                animationDrawable.selectDrawable(0);
                animationDrawable.stop();
            }
        }
    }
}
